import requests
# 执行API调用并存储响应
url = "https://api.github.com/search/repositories?q=language:C&sort=stars"
headers = {"Accept": "application/vnd.github.v3_json"}
r = requests.get(url, headers=headers)
print(f"status_code: {r.status_code}")
# 将API响应赋给一个变量
response_dict = r.json()
print(f"Total_repositories:{response_dict["total_count"]}")
# 探索有关仓库的信息
repo_dicts = response_dict["items"]
print(f"Repositories_returned: {len(repo_dicts)}")
print("\nselected information about each repository: ")
for repo_dict in repo_dicts:
	print(f"\nname: {repo_dict["name"]}")
	print(f"owner: {repo_dict["owner"]["login"]}")
	print(f"stars: {repo_dict["stargazers_count"]}")
	print(f"repository: {repo_dict["html_url"]}")
	print(f"description:{repo_dict["description"]}")
# 研究第一个仓库
# repo_dict = repo_dicts[0]
# # print(f"\nKeys: {len(repo_dict)}")
# print("\nSelected_information about first repository: ")
# print(f"name: {repo_dict["name"]}")
# print(f"owner: {repo_dict["owner"]["login"]}")
# print(f"stars: {repo_dict["stargazers_count"]}")
# print(f"repository: {repo_dict["html_url"]}")
# print(f"created: {repo_dict["created_at"]}")
# print(f"updated: {repo_dict["updated_at"]}")
# print(f"description: {repo_dict["description"]}")
# for key in sorted(repo_dict.keys()):
#	print(key)
# 处理结果
# print(response_dict.keys())
